package base_grammar

import "fmt"

/*
	接口嵌套
*/

type Flyer interface {
	fly()
}

type Swimmer interface {
	swim()
}

type FlyFish interface {
	Flyer
	Swimmer
}

type Fish struct {
	name string
}

func (fish Fish) fly() {
	fmt.Printf("fish.name: %v fly...\n", fish.name)
}

func (fish Fish) swim() {
	fmt.Printf("fish.name: %v swim...\n", fish.name)
}

func interface_f1() {
	var flyFish FlyFish
	// 多态
	flyFish = Fish{name: "鲤鱼"}
	flyFish.fly()
	flyFish.swim()
}

func Interface_test3() {
	//接口嵌套
	// interface_f1()
	interface_f2()
}

func interface_f2() {
	// 多态
	dog := Dog2{}
	cat := Cat2{}
	person := Person{}
	person.care(dog)
	person.care(cat)
}

type Pet2 interface {
	eat2()
	sleep2()
}

type Dog2 struct {
	name string
}

func (dog Dog2) eat2() {
	fmt.Println("dog eating")
}

func (dog Dog2) sleep2() {
	fmt.Println("dog sleeping")
}

type Cat2 struct {
	name string
}

func (cat Cat2) eat2() {
	fmt.Println("cat eating")
}

func (cat Cat2) sleep2() {
	fmt.Println("cat sleeping")
}

type Person struct {
	name string
}

func (person Person) care(pet Pet2) {
	pet.eat2()
	pet.sleep2()
}
